Pack on virtual fields - #1322
Conversation
Yurlungur
left a comment
There was a problem hiding this comment.
This is very cool and I like it a lot. It definitely needs a bit of documentation though. Though I suppose we also don't have documentation for type-based variables, which is sorely needed...
| template <typename T, int... tuv> | ||
| struct TUV_t<T, tuv...> : impl::TUV_t<T, TopologicalElement::CC, tuv...> {}; | ||
|
|
||
| template <typename T, TopologicalElement te, int... tuv> | ||
| struct TUV_t<T, te, tuv...> : impl::TUV_t<T, te, tuv...> {}; |
There was a problem hiding this comment.
with the variadics is this going to get correctly resolved?
There was a problem hiding this comment.
I think so, since the TE & ints are different types. Happy to add some static asserts like this to the unit tests to demonstrate. Unless there is a different edge case you're thinking of?
| // Concept to state that a typed-field is dependent on other | ||
| // fields, and is not itself an actual indexable field. |
There was a problem hiding this comment.
should the concepts stuff be in concepts_lite or should it be here?
There was a problem hiding this comment.
It seemed specialized enough to the pack types that I put it here, but if the convention is to have all concepts in concepts_lite I'm happy to move it
| template <typename, typename, typename...> | ||
| struct UnionTypeLists {}; | ||
|
|
||
| template <typename... Ts> | ||
| struct UnionTypeLists<TypeList<Ts...>, TypeList<>> { | ||
| using type = TypeList<Ts...>; | ||
| }; | ||
|
|
||
| template <typename... Ts, typename V, typename... Vs> | ||
| struct UnionTypeLists<TypeList<Ts...>, TypeList<V, Vs...>> { | ||
| using TL = TypeList<Ts...>; | ||
| using type = std::conditional_t< | ||
| TL::template IsIn<V>(), TL, | ||
| typename UnionTypeLists<TypeList<Ts..., V>, TypeList<Vs...>>::type>; | ||
| }; | ||
|
|
||
| template <typename T, typename U, typename V, typename... Args> | ||
| struct UnionTypeLists<T, U, V, Args...> { | ||
| using type = typename UnionTypeLists<typename UnionTypeLists<T, U>::type, V>::type; | ||
| }; |
There was a problem hiding this comment.
I'm surprised there isn't functionality for this in the standard
| // Get a TypeList of all the non-dependent variables that make up the requested types. | ||
| template <typename... Ts> | ||
| using all_dependent_variables_t = decltype(impl::AllDependentVariables::get(Ts()...)); |
There was a problem hiding this comment.
The name and the comment disagree. Is this all dependent variables or all independent variables?
There was a problem hiding this comment.
The types should be renamed. It is all the independent variables pulled out from the dependent variables
|
Also changelog and mark non-wip :) |
Happy to add both in this PR. |
|
This is very cool! I am wondering though about how complex the template stuff needs to be. Why can't we just do something like class my_derived_var_t : public variable_names::dependent_var_base_t<...> {
...
template <class pack_t>
KOKKOS_INLINE_FUNCTION
Real evaluate(const pack_t &pack, int b, TopologicalElemet te, int k, int j, int i) {
return pack(b, var1_t(), te, k, j, i) + pack(b, var2_t(), te, k, j, i);
}
};and template <class TIn, REQUIRES(IncludesType<TIn, Ts...>::value && std::is_base_of_v<dependent_var_base_t, TIn>)>
KOKKOS_INLINE_FUNCTION Real operator()(const int b, const TE el, const TIn &t,
const int k, const int j, const int i) const {
return t.evaluate(*this, b, te, k, j, i);
}I think there are obviously some circular dependencies that could crop up here (e.g. |
That is much simpler and I think would work just fine. My thought was that it would be nice to make it easy to unit test the |
|
I just got the chance to look at this PR. Quite of few of our targeted use cases would involve either stencil based ops and/or other information (say an adiabatic index). How big of a lift do you think this would be (asking from the point of view whether we should get this interface in as is [pending review comments] or spend "just a little" more time on getting a more flexible version in first place). |
I think luke's suggestion would be pretty easy to implement and would be a better starting place for this kind of feature. |
2786e1e to
b071c5a
Compare
|
@acreyes do we still want to merge this? I'm still pretty excited about it |
Yeah it is something I want to use as well. I think @pgrete wanted to review. Looking at #1415 I think that the |
|
Sounds good. @pgrete can you review? |
| Slicing into ``SparsePack``\ s with ``SubPack``\ s | ||
| -------------------------------------------------- | ||
|
|
||
| A `SubPack` provdies a view into a slice of a `SparsePack` along a given dimension(s). | ||
| `SubPack`\ s are constructed with a block + `kji` index to give a slice into the | ||
| fields at the meshblock + cell index. When a `SubPack` is constructed with the | ||
| `Axis` template parameters then the `SubPack` also providies a view into slices | ||
| of the `SparsePack` along the provided axes offset from the provided `ijk` indices. |
There was a problem hiding this comment.
I think a lot of this has overlap with the pack_views in my loop abstraction PR. We should think about if there is a way to combine things, but maybe after this is merged.
There was a problem hiding this comment.
Probably it is mostly orthogonal after I have looked some more. I could change pack_views to support virtual variables, but that would be separate from SubPacks.
There was a problem hiding this comment.
I was thinking of redoing this on top of the pack_views. My first look at what you added seemed to me like it would be pretty straightforward.
There was a problem hiding this comment.
pack_views are pretty tightly coupled to the loop abstraction stuff, so maybe not a replacement unless everyone switched to the loop abstraction.
lroberts36
left a comment
There was a problem hiding this comment.
LGTM! I think one of my comments was free floating instead of part of the review.
|
|
||
| template <class... Ts, class MT> | ||
| template <class... Ts, class MT, | ||
| REQUIRES(!variable_names::dependent_variable_v<Ts> && ...)> |
There was a problem hiding this comment.
| REQUIRES(!variable_names::dependent_variable_v<Ts> && ...)> | |
| requires(!variable_names::dependent_variable_v<Ts> && ...)> |
|
|
||
| template <class... Ts, class MT> | ||
| template <class... Ts, class MT, | ||
| REQUIRES(!variable_names::dependent_variable_v<Ts> && ...)> |
There was a problem hiding this comment.
| REQUIRES(!variable_names::dependent_variable_v<Ts> && ...)> | |
| requires(!variable_names::dependent_variable_v<Ts> && ...)> |
| } | ||
|
|
||
| template <class... Ts, class MT, | ||
| REQUIRES(variable_names::dependent_variable_v<Ts> || ...)> |
There was a problem hiding this comment.
| REQUIRES(variable_names::dependent_variable_v<Ts> || ...)> | |
| requires(variable_names::dependent_variable_v<Ts> || ...)> |
| Slicing into ``SparsePack``\ s with ``SubPack``\ s | ||
| -------------------------------------------------- | ||
|
|
||
| A `SubPack` provdies a view into a slice of a `SparsePack` along a given dimension(s). | ||
| `SubPack`\ s are constructed with a block + `kji` index to give a slice into the | ||
| fields at the meshblock + cell index. When a `SubPack` is constructed with the | ||
| `Axis` template parameters then the `SubPack` also providies a view into slices | ||
| of the `SparsePack` along the provided axes offset from the provided `ijk` indices. |
There was a problem hiding this comment.
Probably it is mostly orthogonal after I have looked some more. I could change pack_views to support virtual variables, but that would be separate from SubPacks.
086c4bb to
0129de7
Compare
PR Summary
This PR allows for type-based packs to pack "virtual" fields that don't exist in memory, but can be evaluated from their own set of dependent variables in the pack by calling a provided
evaluatefunction.This seems related to #1228, but doesn't provide that capability for outputs as mentioned for ADIOS2.
Also adds
SubPacksto provide stencil (0, 1, 2, & 3D) views into a pack centered on a meshblock and ijk index. This can simplify the need to pass around extra indices in theevaluatefunctions for virtual fields.PR Checklist